package com.example.yyjgit.Controller;


import com.example.yyjgit.Entity.Newss;
import com.example.yyjgit.Entity.ResultEntity;
import com.example.yyjgit.Service.NewssService;
import com.example.yyjgit.Util.JSONTool;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/NewssList")
public class NewssController {
    ResultEntity resultEntity=null;
    @Resource
    NewssService newssService;


    /**
     * 查询所有
     * @param
     * @return
     */
    @GetMapping("news1")
    private  String news(){

        try {
            resultEntity=new ResultEntity();
            List<Newss> list=newssService.getNewssList();
            if (list!=null){
                resultEntity.setCode("0");
                resultEntity.setMsg("查询成功");
                resultEntity.setCount(list.size());
                resultEntity.setData(list);
            }
        }catch (Exception e){
            e.printStackTrace();
            resultEntity.setCode("99999");
            resultEntity.setMsg("查询失败"+e.getMessage());
        }
        return  JSONTool.getJsonTool().toJson(resultEntity);
    }


}
